package com.atwork.wuhua.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.atwork.wuhua.R;
import com.atwork.wuhua.bean.CommunityBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class CommunityAdapter extends BaseQuickAdapter<CommunityBean, BaseViewHolder> {

    private Context context;
    private CommunityImgAdapter communityImgAdapter;


    public CommunityAdapter(Context context, int layoutResId, @Nullable List<CommunityBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, CommunityBean item) {
        helper.addOnClickListener(R.id.img_thumb).addOnClickListener(R.id.tv_content)
                .addOnClickListener(R.id.lly_zan).addOnClickListener(R.id.lly_comment)
                .addOnClickListener(R.id.lly_collection);
        if (item.getCode().equals("1")) {
            helper.getView(R.id.img_big).setVisibility(View.VISIBLE);
            helper.getView(R.id.tv_community).setVisibility(View.GONE);
        } else {
            helper.getView(R.id.img_big).setVisibility(View.GONE);
            helper.getView(R.id.tv_community).setVisibility(View.VISIBLE);

            GridLayoutManager manager = new GridLayoutManager(mContext, 3);
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            ((RecyclerView) helper.getView(R.id.tv_community)).setLayoutManager(manager);
            communityImgAdapter = new CommunityImgAdapter(context, R.layout.item_community_img, item.getDataBeans());
            ((RecyclerView) helper.getView(R.id.tv_community)).setAdapter(communityImgAdapter);
        }

    }
}
